package com.work.music.dao;

import com.work.music.entity.MusicAlbum;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface MusicAlbumMapper {
    @Delete({
        "delete from music_album",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into music_album (uid, songster_id, ",
        "name, cover, synopsis, ",
        "addtime, addip, ",
        "status, reason)",
        "values (#{uid,jdbcType=BIGINT}, #{songsterId,jdbcType=BIGINT}, ",
        "#{name,jdbcType=VARCHAR}, #{cover,jdbcType=VARCHAR}, #{synopsis,jdbcType=VARCHAR}, ",
        "#{addtime,jdbcType=TIMESTAMP}, #{addip,jdbcType=VARCHAR}, ",
        "#{status,jdbcType=INTEGER}, #{reason,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(MusicAlbum record);

    @Select({
        "select",
        "id, uid, songster_id, name, cover, synopsis, addtime, addip, status, reason",
        "from music_album",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="uid", property="uid", jdbcType=JdbcType.BIGINT),
        @Result(column="songster_id", property="songsterId", jdbcType=JdbcType.BIGINT),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="cover", property="cover", jdbcType=JdbcType.VARCHAR),
        @Result(column="synopsis", property="synopsis", jdbcType=JdbcType.VARCHAR),
        @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR)
    })
    MusicAlbum selectByPrimaryKey(Long id);

    @Select({
        "select",
        "id, uid, songster_id, name, cover, synopsis, addtime, addip, status, reason",
        "from music_album"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="uid", property="uid", jdbcType=JdbcType.BIGINT),
        @Result(column="songster_id", property="songsterId", jdbcType=JdbcType.BIGINT),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="cover", property="cover", jdbcType=JdbcType.VARCHAR),
        @Result(column="synopsis", property="synopsis", jdbcType=JdbcType.VARCHAR),
        @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR)
    })
    List<MusicAlbum> selectAll();

    @Update({
        "update music_album",
        "set uid = #{uid,jdbcType=BIGINT},",
          "songster_id = #{songsterId,jdbcType=BIGINT},",
          "name = #{name,jdbcType=VARCHAR},",
          "cover = #{cover,jdbcType=VARCHAR},",
          "synopsis = #{synopsis,jdbcType=VARCHAR},",
          "addtime = #{addtime,jdbcType=TIMESTAMP},",
          "addip = #{addip,jdbcType=VARCHAR},",
          "status = #{status,jdbcType=INTEGER},",
          "reason = #{reason,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(MusicAlbum record);

    /**
     * @param songster_id
     * @author Super-L
     * @creed: 更改原先uid错误传参，增加歌手id-->songster_id,去掉状态判断，改为status = 1
     * @date 2020-05-04 21:48
     * @return java.util.List<com.work.music.entity.MusicAlbum>
     */
    @Select({
            "select",
            "id, uid, songster_id, name, cover, synopsis, addtime, addip, status, reason",
            "from music_album",
            "where",
            "status = 1 and",
            // "songster_id = {uid}"
            "songster_id=#{songster_id}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="uid", property="uid", jdbcType=JdbcType.BIGINT),
            @Result(column="songster_id", property="songsterId", jdbcType=JdbcType.BIGINT),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="cover", property="cover", jdbcType=JdbcType.VARCHAR),
            @Result(column="synopsis", property="synopsis", jdbcType=JdbcType.VARCHAR),
            @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR),
            @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
            @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR)
    })
    List<MusicAlbum> getAlbumListByUid(@Param("songster_id") long songster_id);
}